How to set the sample rates of a sound driver.

In a proper sound driver, the driver supplies a number of available sample rates that the driver will support when given the IOCTL B_AUDIO_GET_PREFERRED_SAMPLE_RATES.  BeOS's interface to the sound driver will then set the driver with the IOCTL B_AUDIO_SET_AUDIO_FORMAT and SOUND_SET_PARAMS.  This I have not gotten to work properly yet, but I have seen some code that does seem to work so I hope to figure it out soon.

Reading the 'Sound Driver Overview' I found if your driver is just called 'sound' and place in the 'dev/audio/old' folder that it will automaticly default to 16kHz as the sampling rate, this works but I found aliasing problems  

Basicly we have to set the speed we want, then force it to stay there otherwise BeOS will try and set the sample rate 16000 per second.  This is done by setting the floating point value of the struc AudioFormat.sample_rate to the sample rate needed and also using the equivlent enum sample_rate into the struc sound->sample_rate.  However, in my tests not all the documented enums worked!  

Trying the diffirent emun sample_rate I found the following results.

kHz_8_0    should equal  8000.0Hz and does measure as  8000 samples per second.
kHz_5_51   should equal  5512.5Hz but measures as     44100 samples per second.
kHz_16_0   should equal 16000.0Hz and does measure as 16000 samples per second.
kHz_11_025 should equal 11025.0Hz and does measure as 11025 samples per second.
kHz_27_42  should equal 27425.0Hz but measures as     44100 samples per second.
kHz_18_9   should equal 18900.0Hz but measures as     44100 samples per second.
kHz_32_0   should equal 32000.0Hz and does measure as 32000 samples per second.
kHz_22_05  should equal 22050.0Hz and does measure as 22050 samples per second.
enum = 8   should equal ?????.0Hz but measures as     44100 samples per second.
kHz_37_8   should equal 37800.0Hz but measures as     44100 samples per second.
enum = 10  should equal ?????.0Hz but measures as     44100 samples per second.
kHz_44_1   should equal 44100.0Hz and does measure as 44100 samples per second.
kHz_48_0   should equal 48000.0Hz and does measure as 48000 samples per second.
kHz_33_075 should equal 33075.0Hz but measures as     44100 samples per second.
kHz_9_6    should equal  9600.0Hz but measures as     44100 samples per second.
kHz_6_62   should equal  6625.0Hz but measures as     44100 samples per second.


